#coding:utf-8
def send_mail(receiver,subject,body,username,password):  
    import smtplib  
    from email.mime.text import MIMEText  
    from email.header import Header    
    smtpserver = 'smtp.qq.com'   
    msg = MIMEText(body,'text','utf-8')  
     #如果需要使用html的，这里就要改为msg = MIMEText(body,'html','utf-8')  
    msg['Subject'] = Header(subject, 'utf-8')  
    try:  
        smtp = smtplib.SMTP()  
        smtp.connect('smtp.qq.com')  
        smtp.login(username, password)  
        smtp.sendmail(username, receiver, msg.as_string())  
        smtp.quit()  
        print '发送成功'  
    except Exception, e:  
        print str(e)  
        print '发送失败' 
if __name__ == '__main__':
    receiver="181911116@qq.com"
    subject="好人一个"
    body="sdasdsafsafsaf"
    username="root"
    password="WaHaHa"
    send_mail(receiver,subject,body,username,password)  
    exit(0)        
